import React from 'react';
import isEqual from 'lodash/isEqual';
import { Button, message, Modal, Menu } from 'antd';

const Item = Menu.Item;
import { WeaTools, WeaDialog, WeaRightMenu, WeaBrowser, WeaInput, WeaTableEditable, WeaLocaleProvider, WeaHelpfulTip } from 'ecCom';
import { inject, observer } from 'mobx-react/index';

const getLabel = WeaLocaleProvider.getLabel;

@inject('portalThemeStore')
@observer
class E9FreqUseMenuSettingNew extends React.Component {
    state = {
        visible: false,
        loading: false,
        treeData: [],
        checkedKeys: [],
        halfCheckedKeys: [],
        expandedKeys: [],
        datas: [],
        ids: [],
        selectedKeys: [],
        showDrop: false,
    };
    constructor(props) {
        super(props);
        this.getRightMenus = this.getRightMenus.bind(this);
        this.onRightMenuClick = this.onRightMenuClick.bind(this);
        this.getData = this.getData.bind(this);
        this.onSave = this.onSave.bind(this);
        this.onCancel = this.onCancel.bind(this);
        this.onChange = this.onChange.bind(this);
        this.getRowSelection = this.getRowSelection.bind(this);
        this.onChangeSub = this.onChangeSub.bind(this);
        this.getColumns = this.getColumns.bind(this);
        this.onShowDrop = this.onShowDrop.bind(this);
        this.onChangeBrowser = this.onChangeBrowser.bind(this);
        this.onChangeBrowser1 = this.onChangeBrowser1.bind(this);
        this.onChangeMenuName = this.onChangeMenuName.bind(this);
        this.getValidator = this.getValidator.bind(this);
        this.onAddTab = this.onAddTab.bind(this);
        this.uuid = this.uuid.bind(this);
        // this.getMType = this.getMType.bind(this);
        // this.getMenuid = this.getMenuid.bind(this);
    }

    render() {
        const { visible, loading, datas } = this.state;
        const { account = {} } = this.props;
        const footer = [
            <div style={{ display: 'inline-block', paddingRight: '12px' }}><Button ecId={`${this && this.props && this.props.ecId || ''}_Button@n9lh3v`} key="save" type="primary" onClick={this.onSave}>{getLabel(30986, '保存')}</Button></div>,
        account.userid == 1 && <div style={{ display: 'inline-block' }}>
    <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@mnxami`}
      type={194}
      tabs={[
                { key: '2', name: getLabel(130619, '按列表'), selected: false, dataParams: { list: 1 } },
        { key: '1', name: getLabel(384541, '按组织架构'), selected: false },
    ]}
      customized
      isSingle={false}
      inputStyle={{ width: '300px', marginLeft: '-31px' }}
      onChange={ids => this.onChangeSub(ids)}
      title={getLabel(25332, '组织结构')}
    >
    <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@8i5no0`} style={{ marginRight: '10px' }} type="primary">{getLabel(390658, '同步到按钮')}</Button>
        </WeaBrowser>
        </div>,
        <div style={{ display: 'inline-block' }}><OperateMenu ecId={`${this && this.props && this.props.ecId || ''}_OperateMenu@o9o62z`} dropMenuDatas={this.getRightMenus()} onShowDrop={this.onShowDrop} onDropMenuClick={this.onRightMenuClick} showDrop={this.state.showDrop}><Button ecId={`${this && this.props && this.props.ecId || ''}_Button@c88jw4`} onClick={this.onShowDrop}>{getLabel(17499, '更多')}&gt;&gt;</Button></OperateMenu></div>,
    ];
        return (
            <div onClick={this.getData}>
            {this.props.children}
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@gxs438`}
              visible={visible}
              title={getLabel(385807, '常用菜单设置')}
              icon="icon-coms-portal"
              iconBgcolor="#1a57a0"
              buttons={footer}
              style={{ width: '50%', height: 524 }}
              onCancel={this.onCancel}
              hasScroll={true}
              loading={loading}
            >
            <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@bq4v2u`} inDialog={true} datas={this.getRightMenus()} onClick={this.onRightMenuClick}>
            <div style={{ clear: 'both' }} />
        <WeaTableEditable ecId={`${this && this.props && this.props.ecId || ''}_WeaTableEditable@79bsub`}
          ref={(el) => { this.table = el; }}
          showCopy={false}
          datas={datas}
          getRowSelection={this.getRowSelection}
          columns={this.getColumns()}
          validator={this.getValidator()}
          willAdd={this.onAddTab}
          draggable={true}
          onChange={(datas) => {
            this.setState({ datas });
        }}
          willEdit={(datas, record = {}) => {
            if (record.key == 'menutype') {
                let _datas = datas;
                _datas[record.index].menuname = '';
                _datas[record.index].menulink = '';
                _datas[record.index].menunamemultlang = '';

                this.setState({
                    datas: _datas,
                });
            } else {
                this.setState({
                    datas,
                });
            }
        }}
        />
        </WeaRightMenu>
        </WeaDialog>

        </div>
    );
    }

    componentWillReceiveProps(nextProps) {
        if (!isEqual(nextProps.value, this.props.value)) {
            this.setState({
                datas: nextProps.value,
            });
        }
    }
    onChange(datas) {
        datas.map((item) => {
            if (item.menutype == 'input') {
                item.menulink = item.menutype1[1];
            } else if (item.menutype == 'browser') {
                // item.menulink = item.menutype1[1].names;
            }
        });
        this.setState({
            datas,
        });
    }

    onAddTab() {
        const { datas } = this.state;
        let newdatas = [...datas];
        newdatas.push({
            id: this.uuid(),
            key: newdatas.length,
            menulink: '',
            menuname: '',
            linktype: '0',
            menutype: '0',
            menuid: '0',
            mType: '0',
        });
        this.setState({
            datas: newdatas,
        });
    }

    uuid() {
        let s = [];
        let hexDigits = '0123456789abcdef';
        for (let i = 0; i < 36; i++) {
            s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
        }
        s[14] = '4'; // bits 12-15 of the time_hi_and_version field to 0010
        s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
        s[8] = '-';
        s[13] = '-';
        s[18] = '-';
        s[23] = '-';
        let uuid = s.join('');
        return uuid;
    }

    getValidator() {
        const validator = {
            rules: {
                menunamemultlang: 'required',
                menuname: 'required',
            },
            errorMessage: {
                // 自定义对应规则的错误提示信息
                required: getLabel(385869, '此项必填'),
            },
        };
        return validator;
    }

    onChangeBrowser(ids, names, da, data = [], index, string) {
        const { datas } = this.state;
        let Mtype = '';
        if (da.length != 0) {
            Mtype = da[0].sourcetype;
        }

        let _datas = [...datas];
        if (string == 'portalmenu') {
            if (data.length == 0) {
                _datas[index].menunamemultlang = '';
                _datas[index].menuname = '';
                _datas[index].menulink = '';
            } else {
                _datas[index].menunamemultlang = names;
                _datas[index].menuname = names;
                _datas[index].mType = (typeof (Mtype) == 'undefined' ? '' : (Mtype == 1 ? 'left' : (Mtype == 2 ? 'top' : (Mtype == 4 ? 'page' : 'custom'))));
                _datas[index].menuid = ids;// new
                if (data[0].fullrouteurl && data[0].fullrouteurl !== '') {
                    _datas[index].menulink = data[0].fullrouteurl;
                } else if (data[0].linkAddress && datas[0].linkAddress !== '') {
                    _datas[index].menulink = data[0].linkAddress;
                }
            }
            this.setState({ datas: _datas });
        } else if (string == 'systempage') {
            if (data[0].activeKey == '1') {
                _datas[index].menulink = data[0].dropMenuUrl + ids;
                if (data[0].dropMenuValue == '1') {
                    _datas[index].menunamemultlang = getLabel(1986, '新建文档');
                    _datas[index].menuname = getLabel(1986, '新建文档');
                } else if (data[0].dropMenuValue == '2') {
                    _datas[index].menunamemultlang = getLabel(1212, '我的文档');
                    _datas[index].menuname = getLabel(1212, '我的文档');
                } else if (data[0].dropMenuValue == '3') {
                    _datas[index].menunamemultlang = getLabel(16397, '最新文档');
                    _datas[index].menuname = getLabel(16397, '最新文档');
                } else if (data[0].dropMenuValue == '4') {
                    _datas[index].menunamemultlang = getLabel(16398, '文档目录');
                    _datas[index].menuname = getLabel(16398, '文档目录');
                }
            } else if (data[0].activeKey == '2') {
                let arr = ids.split(',');
                let wftypeIds = [];
                let wfIds = [];
                arr.map((item) => {
                    if (item.lastIndexOf('wftype') != -1) {
                        wftypeIds.push(item.split('wftype_').join(''));
                    } else {
                        wfIds.push(item.split('wf_').join(''));
                    }
                });
                data.map((item) => {
                    if (item.allVersionIds && item.allVersionIds != '') {
                        const allVersionIdsArrs = item.allVersionIds.split(',');
                        if (allVersionIdsArrs.length > 1) {
                            allVersionIdsArrs.map((allVersionIdsItem) => {
                                if (allVersionIdsItem != '') {
                                    wfIds.push(allVersionIdsItem);
                                }
                            });
                        } else {
                            wfIds.push(allVersionIdsArrs.join(''));
                        }
                    }
                });
                let viewType = '';
                if (data[0].dropMenuValue == '1') {
                    _datas[index].menunamemultlang = getLabel(84759, '新建流程');
                    _datas[index].menuname = getLabel(84759, '新建流程');
                    let jsonstr = `wfRange=${wfIds.toString()}`;
                    _datas[index].menulink = data[0].dropMenuUrl + jsonstr;
                    this.setState({ datas: _datas });
                    return;
                } else if (data[0].dropMenuValue == '2') {
                    _datas[index].menunamemultlang = getLabel(1207, '待办事宜');
                    _datas[index].menuname = getLabel(1207, '待办事宜');
                    viewType = '1';
                } else if (data[0].dropMenuValue == '3') {
                    _datas[index].menunamemultlang = getLabel(84758, '已办事宜');
                    _datas[index].menuname = getLabel(84758, '已办事宜');
                    viewType = '2';
                } else if (data[0].dropMenuValue == '4') {
                    _datas[index].menunamemultlang = getLabel(17992, '办结事宜');
                    _datas[index].menuname = getLabel(17992, '办结事宜');
                    viewType = '3';
                } else if (data[0].dropMenuValue == '5') {
                    _datas[index].menunamemultlang = getLabel(21639, '抄送事宜');
                    _datas[index].menuname = getLabel(21639, '抄送事宜');
                    viewType = '5';
                } else if (data[0].dropMenuValue == '6') {
                    _datas[index].menunamemultlang = getLabel(21640, '督办事宜');
                    _datas[index].menuname = getLabel(21640, '督办事宜');
                    viewType = '6';
                } else if (data[0].dropMenuValue == '7') {
                    _datas[index].menunamemultlang = getLabel(1210, '我的请求');
                    _datas[index].menuname = getLabel(1210, '我的请求');
                    viewType = '4';
                }
                let jsonstr = {
                    flowids: wfIds,
                    viewType,
                    typeids: wftypeIds,
                    isExclude: 0,
                };
                if (viewType == '2') {
                    jsonstr = {
                        flowids: wfIds,
                        viewType,
                        typeids: wftypeIds,
                        isExclude: 0,
                        isArrangement: 1,
                    };
                } else if (viewType == '1') {
                    jsonstr = {
                        flowids: wfIds,
                        viewType,
                        typeids: wftypeIds,
                        isExclude: 0,
                        showView: 1,
                    };
                } else if (viewType == '6') { // 督办
                    let jsonstr = `workflowId=${wfIds.toString()}`;
                    _datas[index].menulink = data[0].dropMenuUrl + escape(JSON.stringify(jsonstr));
                    _datas[index].menulink = `/spa/workflow/index_mobx.jsp#/main/workflow/supervise?fromwhere=jsonFilter&${jsonstr}`;
                    this.setState({ datas: _datas });
                    return;
                }
                _datas[index].menulink = data[0].dropMenuUrl + escape(JSON.stringify(jsonstr));
            }
            this.setState({ datas: _datas });
        }
    }


    onChangeBrowser1(ids, names, data = [], index, string) {
        const { datas } = this.state;
        let _datas = [...datas];
         if (string == 'systempage' && data.length > 0) {
            if (data[0].activeKey == '1') {
                _datas[index].menulink = data[0].dropMenuUrl + ids;
                if (data[0].dropMenuValue == '1') {
                    _datas[index].menunamemultlang = getLabel(1986, '新建文档');
                    _datas[index].menuname = getLabel(1986, '新建文档');
                } else if (data[0].dropMenuValue == '2') {
                    _datas[index].menunamemultlang = getLabel(1212, '我的文档');
                    _datas[index].menuname = getLabel(1212, '我的文档');
                } else if (data[0].dropMenuValue == '3') {
                    _datas[index].menunamemultlang = getLabel(16397, '最新文档');
                    _datas[index].menuname = getLabel(16397, '最新文档');
                } else if (data[0].dropMenuValue == '4') {
                    _datas[index].menunamemultlang = getLabel(16398, '文档目录');
                    _datas[index].menuname = getLabel(16398, '文档目录');
                }
            } else if (data[0].activeKey == '2') {
                let arr = ids.split(',');
                let wftypeIds = [];
                let wfIds = [];
                arr.map((item) => {
                    if (item.lastIndexOf('wftype') != -1) {
                        wftypeIds.push(item.split('wftype_').join(''));
                    } else {
                        wfIds.push(item.split('wf_').join(''));
                    }
                });
                data.map((item) => {
                    if (item.allVersionIds && item.allVersionIds != '') {
                        const allVersionIdsArrs = item.allVersionIds.split(',');
                        if (allVersionIdsArrs.length > 1) {
                            allVersionIdsArrs.map((allVersionIdsItem) => {
                                if (allVersionIdsItem != '') {
                                    wfIds.push(allVersionIdsItem);
                                }
                            });
                        } else {
                            wfIds.push(allVersionIdsArrs.join(''));
                        }
                    }
                });
                let viewType = '';
                if (data[0].dropMenuValue == '1') {
                    _datas[index].menunamemultlang = getLabel(84759, '新建流程');
                    _datas[index].menuname = getLabel(84759, '新建流程');
                    let jsonstr = `wfRange=${wfIds.toString()}`;
                    _datas[index].menulink = data[0].dropMenuUrl + jsonstr;
                    this.setState({ datas: _datas });
                    return;
                } else if (data[0].dropMenuValue == '2') {
                    _datas[index].menunamemultlang = getLabel(1207, '待办事宜');
                    _datas[index].menuname = getLabel(1207, '待办事宜');
                    viewType = '1';
                } else if (data[0].dropMenuValue == '3') {
                    _datas[index].menunamemultlang = getLabel(84758, '已办事宜');
                    _datas[index].menuname = getLabel(84758, '已办事宜');
                    viewType = '2';
                } else if (data[0].dropMenuValue == '4') {
                    _datas[index].menunamemultlang = getLabel(17992, '办结事宜');
                    _datas[index].menuname = getLabel(17992, '办结事宜');
                    viewType = '3';
                } else if (data[0].dropMenuValue == '5') {
                    _datas[index].menunamemultlang = getLabel(21639, '抄送事宜');
                    _datas[index].menuname = getLabel(21639, '抄送事宜');
                    viewType = '5';
                } else if (data[0].dropMenuValue == '6') {
                    _datas[index].menunamemultlang = getLabel(21640, '督办事宜');
                    _datas[index].menuname = getLabel(21640, '督办事宜');
                    viewType = '6';
                } else if (data[0].dropMenuValue == '7') {
                    _datas[index].menunamemultlang = getLabel(1210, '我的请求');
                    _datas[index].menuname = getLabel(1210, '我的请求');
                    viewType = '4';
                }
                let jsonstr = {
                    flowids: wfIds,
                    viewType,
                    typeids: wftypeIds,
                    isExclude: 0,
                };
                if (viewType == '2') {
                    jsonstr = {
                        flowids: wfIds,
                        viewType,
                        typeids: wftypeIds,
                        isExclude: 0,
                        isArrangement: 1,
                    };
                } else if (viewType == '1') {
                    jsonstr = {
                        flowids: wfIds,
                        viewType,
                        typeids: wftypeIds,
                        isExclude: 0,
                        showView: 1,
                    };
                } else if (viewType == '6') { // 督办
                    let jsonstr = `workflowId=${wfIds.toString()}`;
                    _datas[index].menulink = data[0].dropMenuUrl + escape(JSON.stringify(jsonstr));
                    _datas[index].menulink = `/spa/workflow/index_mobx.jsp#/main/workflow/supervise?fromwhere=jsonFilter&${jsonstr}`;
                    this.setState({ datas: _datas });
                    return;
                }
                _datas[index].menulink = data[0].dropMenuUrl + escape(JSON.stringify(jsonstr));
            }
            this.setState({ datas: _datas });
        } else {
             _datas[index].menunamemultlang = '';
             _datas[index].menuname = '';
             this.setState({ datas: _datas });
         }
    }

    getColumns() {
        const { datas } = this.state;
        let _datas = [...datas];

        const columns = [
            {
                title: getLabel(385808, '菜单地址'),
                dataIndex: 'menutype',
                display: 'true',
                key: 'menutype',
                width: '15%',
                com: [
                    {
                        label: '',
                        type: 'SELECT',
                        editType: '1', // select 组件属性，参看具体组件
                        key: 'menutype',
                        options: [
                            {
                                key: '0',
                                selected: true,
                                showname: getLabel(33496, '系统菜单'),
                            },
                            {
                                key: '2',
                                selected: false,
                                showname: getLabel(31560, '系统页面'),
                            },
                            {
                                key: '1',
                                selected: false,
                                showname: getLabel(385809, '自定义URL'),
                            },
                        ],
                        width: 120,
                        disabled: false,
                        otherParams: { className: 'test-className' }, // 其它属性，会被平铺到组件上。
                    }],
            }, {
                title: '',
                dataIndex: 'menuname',
                display: 'true',
                key: 'menuname',
                width: '45%',
                com: [
                    {
                        key: 'menuname',
                        type: 'CUSTOM',
                        viewAttr: '3',
                        render: (text, record, index) => {
                            let loginButton = '';
                            if (record.menutype == '0') {
                                let replaceDatas = [];
                                if (record.menulink && record.menuname) {
                                    replaceDatas = [{ id: record.menulink, name: record.menuname }];
                                }
                                loginButton = (
                                    <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@kgx0wq@${record.menuid}`}
                                      icon="icon-coms-portal"
                                      iconBgcolor="#1a57a0"
                                      tabs={[
                                        {
                                            name: getLabel(33675, '前端菜单'),
                                            key: '1',
                                            dataParams: { sourcetype: '1' },
                                            conditionDataParams: { sourcetype: '1' },
                                            // mType:'left'
                                        },
                                {
                                    name: getLabel(33676, '后端菜单'),
                                        key: '2',
                                    dataParams: { sourcetype: '2' },
                                    conditionDataParams: { sourcetype: '2' },
                                    // mType:'top'
                                },
                                {
                                    name: getLabel(18773, '自定义菜单'),
                                        key: '3',
                                    dataParams: { sourcetype: '3' },
                                    conditionDataParams: { sourcetype: '3' },
                                    // mType:'custom'
                                },
                                {
                                    name: getLabel(23094, '系统门户页面'),
                                        key: '4',
                                    dataParams: { sourcetype: '4' },
                                    conditionDataParams: { sourcetype: '4' },
                                    // mType:'system'
                                },
                            ]}
                                      type={'portalmenu'}
                                      title={getLabel(33496, '系统菜单')}
                                      isMultCheckbox={true}
                                      isLoadAll={false}
                                      viewAttr={3}
                                      inputStyle={{ width: '80%' }}
                                      replaceDatas={replaceDatas}
                                      onChange={(ids, names, datas) => {
                                    this.onChangeBrowser(ids, names, datas, datas, index, 'portalmenu');
                                }}
                                    />
                            );
                            } else if (record.menutype == '1') {
                                loginButton = (
                                    <div>
                                    <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@2qe1h8@${record.menuid}`}
                                      style={{ width: '80%' }}
                                      viewAttr={3}
                                      value={record.menulink}
                                      onChange={(value) => {
                                    _datas[index].menulink = value;
                                    _datas[index].menuname = value;
                                    this.setState({ datas: _datas });
                                }}
                                    />
                                <WeaHelpfulTip ecId={`${this && this.props && this.props.ecId || ''}_WeaHelpfulTip@n0hzkf@${record.menuid}`}
                                  style={{ display: 'inline-block', padding: '0 0 8px 15px' }}
                                  width={196} // 如果要自定义宽度，在这里设置
                                  title={getLabel(386567, '外部地址，请在地址前加上http://或https://')}
                                  isCenter={true}
                                />
                                </div>
                            );
                            } else if (record.menutype == '2') {
                                let replaceDatas = [];
                                if (record.menulink && record.menuname) {
                                    replaceDatas = [{ id: record.menulink, name: record.menuname }];
                                }
                                loginButton = (
                                    <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@tmubl9@${record.menuid}`}
                                      tabs={[
                                        { name: getLabel(22243, '文档'), key: '1', dataParams: { sourcetype: '1' } },
                                { name: getLabel(30045, '流程'), key: '2', dataParams: { sourcetype: '2' } },
                            ]}
                                      type={'systempage'}
                                      title={getLabel(31560, '系统页面')}
                                      inputStyle={{ width: '80%' }}
                                      textDecoration={true}
                                      replaceDatas={replaceDatas}
                                      viewAttr={3}
                                      onChange={(ids, names, datas) => {
                                    this.onChangeBrowser1(ids, names, datas, index, 'systempage');
                                }}
                                      isSingle={false}
                                    />);
                            }
                            return (<div className="wea-url">
                                <div className="wea-url-toolbarmore-upload">
                                {loginButton}
                                </div>
                                </div>);
                        },
                    },
                ],
            }, {
                title: getLabel(30173, '打开方式'),
                dataIndex: 'linktype',
                display: 'true',
                key: 'linktype',
                width: '15%',
                com: [
                    {
                        label: '',
                        type: 'SELECT',
                        editType: '1', // select 组件属性，参看具体组件
                        key: 'linktype',
                        options: [
                            {
                                key: '0',
                                selected: true,
                                showname: getLabel(20597, '默认窗口'),
                            },
                            {
                                key: '1',
                                selected: false,
                                showname: getLabel(18717, '弹出窗口'),
                            },
                        ],
                        width: 120,
                    }],
            }, {
                title: getLabel(30828, '显示名称'),
                dataIndex: 'menunamemultlang',
                display: 'true',
                key: 'menunamemultlang',
                width: '15%',
                className: 'xsmc',
                com: [
                    { label: '', type: 'INPUT', viewAttr: 3, editType: '1', key: 'menunamemultlang', width: 120, inputType: 'multilang', isBase64: true },
                ],
            }];
        return columns;
    }

    onChangeMenuName(value, index) {
        const { datas } = this.state;
        let _datas = datas;
        _datas[index].menuname = value;
        this.setState({
            datas: _datas,
        });
    }
    onShowDrop() {
        this.setState({
            showDrop: !this.state.showDrop,
        });
    }

    getRowSelection(rowSelection) {
        let sel = { ...rowSelection };
        sel.getCheckboxProps = record => ({ disabled: record.id == '1' });
        return sel;
    }

    getRightMenus() {
        let rightMenus = [];
        rightMenus.push({ disabled: false, icon: <i className="icon-coms-Preservation" />, content: getLabel(30986, '保存') });
        rightMenus.push({ disabled: false, icon: <i className="icon-coms-content-o" />, content: getLabel(31129, '取消') });
        return rightMenus;
    }

    onRightMenuClick(key) {
        if (key == '0') {
            this.onSave();
        } else if (key == '1') {
            this.onCancel();
        }
    }

    getData() {
        this.setState({ visible: true, loading: true });
        WeaTools.callApi('/api/portal/frequsemenu/getdata', 'POST', {
            parentid: 0,
            setting: 'setting',
        }).then((data) => {
            this.setState({
                loading: false,
                datas: data,
            });
        });
    }

    onSave() {
        const result = this.table.doValidate();
        const { datas } = this.state;
        this.setState({
            loading: true,
        });


        if (result.pass) {
            WeaTools.callApi('/api/portal/frequsemenu/savedata', 'POST', { datas: JSON.stringify(datas) }).then((data) => {
                if (data.status == '2') {
                    message.error(data.errormsg);
                } else {
                    this.setState({
                        loading: false,
                    });
                    message.success(getLabel(83551, '保存成功！'));
                    this.setState({ visible: false });
                    if (this.props.callback && typeof this.props.callback == 'function') {
                        this.props.callback();
                    }
                }
                const { portalThemeStore } = this.props;
                portalThemeStore.getFreqUseMenu();
            });
        }
    }

    onChangeSub(ids) {
        const { datas } = this.state;

        if (ids == null || ids == '') {
            return;
        }
        Modal.confirm({
                title: getLabel(15172, '系统提示'),
                content: <div>
            <div>{getLabel(387399, '确定要同步当前的常用菜单设置到选择的分部吗？')}</div>
        <div style={{ color: 'red' }}>{getLabel(387400, '注意：此操作会删除用户已有的常用菜单')}</div>
        </div>,
        onOk: () => {
            this.setState({
                loading: true,
            });
            WeaTools.callApi('/api/portal/frequsemenu/syncfreqmenu', 'POST', { datas: JSON.stringify(datas), ids }).then((data) => {
                if (data.status == '2') {
                    message.error(data.errormsg);
                } else {
                    message.success(getLabel(387135, '同步成功！'));
                    if (this.props.callback && typeof this.props.callback == 'function') {
                        this.props.callback();
                    }
                }
            });
            this.setState({
                loading: false,
            });
        },
    });
    }

    onCancel() {
        this.setState({ visible: false });
    }
}

export default E9FreqUseMenuSettingNew;


class OperateMenu extends React.Component {
    render() {
        const { dropMenuDatas, onDropMenuClick, onShowDrop, showDrop, children } = this.props;
        const menu = dropMenuDatas
            ? (<Menu ecId={`${this && this.props && this.props.ecId || ''}_Menu@1h91bv`} mode="vertical"
              onClick={(o) => {
            if (typeof onDropMenuClick === 'function') onDropMenuClick(o.key);
            dropMenuDatas.forEach((d) => {
                if (d.key === o.key && typeof d.onClick === 'function') d.onClick(o.key);
            });
        }}
            >
        {
            dropMenuDatas.map((d, i) => (
                    <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@yqr7wu@${d.key || i}`} key={d.key || i} disabled={d.disabled}>
                    <span className="wea-right-menu-icon">{d.icon}</span>
                {d.content}
            </Item>
            ))
        }
    </Menu>)
    : '';
        return (<div className="portal-portalsetting-moremenu-pop">
            <div className="wea-new-top-drop-menu wea-right-menu" style={{ display: showDrop ? 'block' : 'none' }} onMouseLeave={onShowDrop}>
            <div className="wea-right-menu-icon-background" />
        {menu}
    </div>
        {children}
    </div>);
    }
}
